package com.redxiii.spike.util.command;

import java.util.HashMap;
import java.util.Map;

import com.redxiii.spike.api.command.Command;
import com.redxiii.spike.api.command.CommandHelp;
import com.redxiii.spike.api.command.CommandPattern;
import com.redxiii.spike.api.communication.CommunicationService;
import com.redxiii.spike.util.core.EngineSession;

/**
 * @author Daniel Filgueiras
 * @since 19/06/2011
 */
public abstract class AbstractCommand implements Command, CommandHelp {

	private Map<String, String> parsedParameters = new HashMap<String, String>();
	protected CommunicationService service;
	
	public AbstractCommand() {
		this.service = EngineSession.getCommunicationService();
	}
	
	public String getParsedParameter(String key) {
		return parsedParameters.get(key);
	}
	
	public void setParsedParameter(String key, String value) {
		parsedParameters.put(key, value);
	}
	
	public StringBuilder getHelp() {
		
		CommandPattern pattern = this.getClass().getAnnotation(CommandPattern.class);
		
		StringBuilder builder = new StringBuilder()
			.append(this.getClass().getName());
		
		if (pattern != null) {
			for (String ptn : pattern.patterns()) {
				builder.append("\r\n\t").append(ptn);
			}
		}
		
		return null;
	}

}
